!> author: 左志华
!> date: 2022-07-02
!>
!> Mathematics
!> 数学模块
module math_m

    use, intrinsic :: iso_fortran_env, only: rp => real64
    implicit none
    private

    public :: get_distance, r23, rp
    
    real(rp), parameter :: r23 = 2.0_rp/3.0_rp  !! 2/3

contains

    !> Distance between two particles <br>
    !> 粒子之间的距离 (distance)
    pure subroutine get_distance(x, y, d, r)
        real(rp), intent(in), dimension(2) :: x, y  !! x, y: coordinates of the particles
                                                    !! 两点坐标
        real(rp), intent(out), dimension(2) :: d    !! Distance per axis
                                                    !! 坐标轴距离
        real(rp), intent(out) :: r                  !! Euclidean distance
                                                    !! 欧式距离

        d = x - y
        r = norm2(d)

    end subroutine get_distance

end module math_m
